#include "Eventfd.hpp"

#include <unistd.h>

#include <iostream>
#include <thread>


using std::cout;
using std::endl;


struct Mytask
{
    void process()
    {
        srand(time(nullptr));
        int number = rand() % 100;
        printf("make a number: %d\n", number);
    }
};

int main()
{
    xww::Eventfd event(std::bind(&Mytask::process, Mytask()));
    std::thread th(std::bind(&xww::Eventfd::start, &event));

    //sleep(6);
    int cnt = 10;
    while(cnt-- > 0) {
        //主线程通知子线程执行任务
        event.wakeup();
        cout << "\nmain thread notify cnt: " << cnt << endl;

        sleep(1);
    }

    sleep(6);
    event.stop();
    th.join();

    return 0;
}